// {a:1,b:1} => ?a=1&b=1
export function jsonToString(json){
  if(typeof(json) != "object")
    return "";
  var filedNum = 0;
  var str = "?";
  for (const item in json)
    if (json.hasOwnProperty(item)) {
      filedNum++;
      str+=item+"="+json[item]+"&";
    }
  str = str.substr(0,str.length-1);
  if(filedNum>0)
    return str
  else
    return ""
}

//随机数
/***
*liveProbability: 0~10  true的概率
*/
export function liveOrDie(liveProbability){
  debugger;
  if(!liveProbability)
    liveProbability = 5
  if(liveProbability < 10 && liveProbability >= 1)
    return Math.random()*10 < liveProbability
  else if(liveProbability < 1)
    return Math.random()< liveProbability
  else if(liveProbability > 10)
    return Math.random()*100 < liveProbability
}


//判断是PC还是移动
/*
* true:PC
* false:移动
*/
export function isPC() {
  const userAgentInfo = navigator.userAgent;//用户设备
  const Agents = [//移动端设备
    "Android",
    "iPhone",
    "SymbianOS",
    "Windows Phone",
    "iPad",
    "iPod"
    ];
  return Agents.every(e=>!userAgentInfo.includes(e));
}


//随机rgb - //低饱和
export const randomRGB = () =>{
  const randint = Math.floor(Math.random()*255)
  const result = [randint-50,randint,randint+50].sort(()=>{
    return (0.5-Math.random())
  })
  return `rgb(${result})`
}